<template>
  <div>
    <TopFilter ref="formPanel" :list="topFilterList" :cols="3" :labelWidth="90" @filterChange="searchCustomer"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSubmitBtn="false"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      columnsRef="partPartOutboundPartSalesCustomer"
      selectionType="single"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <div>
        <el-button @click="closeDrawer(1)">关 闭</el-button>
        <el-button type="primary" @click="closeDrawer(2)">确 定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { customerList, customerType } from '@/api/part/partOut/partSales/index';
import { getOwnerInfo } from '@/api/customerRepair/vehicleOwnerManagement/vehicleChange';
export default {
  name: 'customer',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      fetchApi: getOwnerInfo, // 调用接口
      fetchParams: { xhrAbort: false }, // 调用数据
      columns: this.createTablelist(),
      selectedRows: []
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    // this.queryCustomer();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '客户代码',
          fieldName: 'ownerNo'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'ownerName'
        },
        // {
        //   type: 'SELECT',
        //   label: '数据来源',
        //   fieldName: 'oemTag',
        //   itemList: this.createDictList('1045')
        // },
        {
          type: 'SELECT',
          label: '客户类别',
          fieldName: 'ownerProperty',
          itemList: this.createDictList('8011')
        }
      ];
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close', true);
      } else {
        if (!this.selectedRows.length) {
          return this.$notify({
            title: '提示信息',
            message: '请选择一条数据',
            type: 'warning'
          });
        }
        if (this.selectedRows.some(x => Number(x.COUNT) <= 0)) {
          return this.$notify({
            title: '提示信息',
            message: '请选择一条数据',
            type: 'warning'
          });
        }
        this.$emit('saveDialog', this.selectedRows);
      }
    },
    createTablelist() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户代码',
          dataIndex: 'ownerNo',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'ownerName',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '客户拼音',
        //   dataIndex: 'CUSTOMER_SPELL',
        //   sorter: true,
        //   showOverflowTooltip: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '客户类别',
          dataIndex: 'ownerProperty',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input',
          dictItems: this.createDictList('8011')
        }
        // {
        //   title: '加价率',
        //   dataIndex: 'PRICE_ADD_RATE',
        //   hidden: true,
        // },
        // {
        //   title: '销售基价',
        //   dataIndex: 'SALES_BASE_PRICE_TYPE',
        //   hidden: true,
        // },
        // {
        //   title: '数据来源',
        //   dataIndex: 'OEM_TAG',
        //   editable: false,
        //   editType: 'select',
        //   editItems: this.createDictList(1045),
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList(1045)
        // }
      ];
    },
    searchCustomer(val) {
      debugger;
      this.fetchParams = Object.assign({}, val);
      this.fetchParams = { ...this.fetchParams };
    },

    // 选中
    selectChange(rows) {
      this.selectedRows = rows;
    }
  }
};
</script>
